package crawler;

import java.io.File;
import java.util.ArrayList;

import org.ini4j.Wini;

public class CrawlerStrategy {
	private static final String SECTION_NAME = "CrawlerStrategy";
	
	public int maxDepth;
	public ArrayList<String> seeds;
	public ArrayList<String> words;
	public String outputPath;
	
	
	private static void convertToArrayList(String str,String sep,ArrayList<String> words)
	{
		if (str == null || sep == null || words == null)
		{
			return;
		}
		String[] arr = str.split(sep);
		
		for(String word : arr)
		{
			words.add(word);
		}
	}
	
	public CrawlerStrategy(String strategyPath) throws Exception
	{
		Wini ini = new Wini(new File(strategyPath));
		seeds = new ArrayList<String>();
		words = new ArrayList<String>();
		
		maxDepth = ini.get(SECTION_NAME,"depth",int.class);
		convertToArrayList(ini.get(SECTION_NAME,"seedsList"),",",seeds);
		convertToArrayList(ini.get(SECTION_NAME,"wordsList"),",",words);
		outputPath = ini.get(SECTION_NAME,"outputPath");
	}
}
